package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketFootprint;
import com.cskaoyan.market.db.domain.MarketFootprintExample;
import com.cskaoyan.market.db.mapper.MarketFootprintMapper;
import com.cskaoyan.market.service.AdminFootprintService;
import com.cskaoyan.market.util.MybatisUtils;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @author:yanzijun
 * @time:2024/06/18/21:36
 */
public class AdminFootprintServiceImpl implements AdminFootprintService {
    @Override
    public List<MarketFootprint> list(String page, String limit, String sort, String order, String userId, String goodsId) {
        SqlSession session = MybatisUtils.getSession();
        MarketFootprintMapper mapper = session.getMapper(MarketFootprintMapper.class);
        MarketFootprintExample marketFootprintExample = new MarketFootprintExample();
        MarketFootprintExample.Criteria criteria = marketFootprintExample.createCriteria();
        if (StringUtils.isNotEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.valueOf(userId));
        }
        if (StringUtils.isNotEmpty(goodsId)) {
            criteria.andGoodsIdEqualTo(Integer.valueOf(goodsId));
        }
        marketFootprintExample.setOrderByClause(sort + " " + order);
        PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
        List<MarketFootprint> list = mapper.selectByExample(marketFootprintExample);
        session.close();
        return list;
    }
}
